﻿Imports Subro.Controls

Public Class StartFRM

#Region " D e k l a r a t i o n e n "
    Private WithEvents EanEngine As New BarCodeEngine
#End Region

#Region " StartFRM_Load-Ereignis "
    Private Sub StartFRM_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Size = SystemInformation.PrimaryMonitorSize

        FülleTestDaten()

    End Sub
#End Region

#Region " ButtonEinstellungen_Click-Ereignis "
    Private Sub ButtonEinstellungen_Click(sender As Object, e As EventArgs) Handles ButtonEinstellungen.Click
        Dim einstellungsFRM As New EinstellungenFRM
        einstellungsFRM.ShowDialog()
    End Sub
#End Region

#Region " ButtonExit_Click-Ereignis "
    Private Sub ButtonExit_Click(sender As Object, e As EventArgs) Handles ButtonExit.Click
        Me.Close()
    End Sub
#End Region

#Region " StartFRM_KeyPress-Ereignis "
    Private Sub StartFRM_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Me.KeyPress
        EanEngine.EingehendesKeyDown(e.KeyChar)
    End Sub
#End Region

#Region " EanEngine_EingehenderScan-Ereignis "
    Private Sub EanEngine_EingehenderScan(ScanErgebnis As String) Handles EanEngine.EingehenderScan
        '>>> Prüfen ob der EAN Code bekannt ist
        Dim eanID As Integer = DB.EanBekannt(ScanErgebnis)
        If eanID = -1 Then
            '>>> Falls nein entsprechendes Form laden
            Dim step2FRM As New NeuVorhandenFRM
            If step2FRM.ShowDialog = DialogResult.OK Then
                Select Case step2FRM.Rückgabe
                    Case NeuVorhanden.Neu
                        Dim step3FRM As New NeuerArtikelFRM(ScanErgebnis)
                        If step3FRM.ShowDialog <> DialogResult.OK Then
                            Exit Sub
                        End If
                        eanID = step3FRM.EanID
                        step3FRM.Dispose()
                    Case NeuVorhanden.Vorhanden
                        Dim step3FRM As New VorhandenerArtikelFRM(ScanErgebnis)
                        If step3FRM.ShowDialog <> DialogResult.OK Then
                            Exit Sub
                        End If
                        eanID = step3FRM.EanID
                        step3FRM.Dispose()
                End Select
            Else
                Exit Sub
            End If
            step2FRM.Dispose()
        End If

        Dim abzugangFRM As New ZugangAbgangFRM
        abzugangFRM.ShowDialog()
        Select Case abzugangFRM.Aktion
            Case ZugangAbgang.Zugang
                Dim BuchungsForm As New ZugangsBuchungFRM(eanID)
                BuchungsForm.ShowDialog()
            Case ZugangAbgang.Abgang

        End Select
    End Sub
#End Region




    Private Sub FülleTestDaten()
        Dim art As String
        Dim tmpDT As New DataTable
        tmpDT.Columns.Add("Artikel")
        tmpDT.Columns.Add("Menge1")
        tmpDT.Columns.Add("Einheit1")
        tmpDT.Columns.Add("Menge2")
        tmpDT.Columns.Add("Einheit2")
        tmpDT.Columns.Add("Verfallsdatum")
        For i = 1 To 15
            If i Mod 3 = 0 Then
                art = "Pepsi"
            ElseIf i Mod 2 = 0 Then
                art = "Mehl"
            Else
                art = "Pizza"
            End If
            Dim tmpRow As DataRow = tmpDT.NewRow
            tmpRow(0) = art
            tmpRow(1) = i
            tmpRow(2) = "Stück"
            tmpRow(3) = i * 2
            tmpRow(4) = "Kg"
            tmpRow(5) = Now.AddMonths(i).ToShortDateString
            tmpDT.Rows.Add(tmpRow)
        Next
        DGV.DataSource = tmpDT
        DGV.Columns(0).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
        DGV.Columns(1).Width = 150
        DGV.Columns(2).Width = 150
        DGV.Columns(3).Width = 150
        DGV.Columns(4).Width = 150
        DGV.Columns(5).Width = 200
        Dim grouper As New Subro.Controls.DataGridViewGrouper(DGV)
        grouper.SetGroupOn("Artikel")
    End Sub
End Class

#Region " Public Enum ZugangAbgang "
Public Enum ZugangAbgang
    Zugang
    Abgang
End Enum
#End Region

#Region " Public Enum NeuVorhanden "
Public Enum NeuVorhanden
    Neu
    Vorhanden
End Enum
#End Region